<template>
	<el-dialog title="NFT统计" :visible.sync="visible" width="1200px">
		<div class="el-box">
			<div class="list-box" id="list-box">
				<el-table :data="list" v-loading="loading" stripe style="width: 100%;"
					header-row-class-name="headcss">
					<el-table-column prop="Level" label="等级" align="center"></el-table-column>
					<el-table-column prop="TotalSupply" label="发行量" align="center"></el-table-column>
					<el-table-column prop="TotalLeft" label="总余量" align="center"></el-table-column>
					<el-table-column prop="TotalSell" label="总销售量" align="center"></el-table-column>
					<el-table-column prop="TotalSyn" label="总合成量" align="center"></el-table-column>
					<el-table-column
						fixed="right"
						label="操作"
						align="center"
						width="180">
					  <template slot-scope="scope">
						<el-button
						  @click.native.prevent="doAction(scope.row,1)"
						  type="text"
						  size="medium">
						  {{scope.row.SellState==1?'关闭售卖':'开启售卖'}}
						</el-button>
						<el-button
						  @click.native.prevent="doAction(scope.row,2)"
						  type="text"
						  v-if="scope.row.Level!=1"
						  size="medium">
						  {{scope.row.SynState==1?'关闭合成':'开启合成'}}
						</el-button>
						
					  </template>
					</el-table-column>
				</el-table>
			</div>
		</div>
	</el-dialog>
</template>

<script>
	import {levelTotalSell,openNftState} from '@/utils/api'
	export default {
		data() {
			return {
				visible: false,
				list: [],
				loading: false,
				currentPage:1,
				size:10,
				total:0,
				addr:''
			}
		},
		methods:{
			async _levelTotalSell(){
				this.loading=true
				let {data,response} = await levelTotalSell({})
				this.loading = false
				this.list = data
			},
			open(addr){
				this.addr = addr
				this.visible=true
				this._levelTotalSell()
			},
			doAction(item,index){
				var that = this
				var txt = index==1?(item.SellState==0?'开放售卖提示':'关闭售卖提示'):(item.SynState==0?'开放合成提示':'关闭合成提示')
				this.$confirm('确定要设置吗?', txt, {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					if(index==1){
						if(item.SellState==0){
							var params = {
								flag: item.Level,
								option:index==1?'open-sale':'open-synable'
							}
						}else{
							var params = {
								flag: item.Level,
								option:index==1?'close-sale':'close-synable'
							}
						}
					}else{
						if(item.SynState==0){
							var params = {
								flag: item.Level,
								option:index==1?'open-sale':'open-synable'
							}
						}else{
							var params = {
								flag: item.Level,
								option:index==1?'close-sale':'close-synable'
							}
						}
						
					}
					openNftState(params).then(r=>{
						if(r.response.errCode==0){
							that.$message.success('设置成功')
							that._levelTotalSell()
						}
					})
				}).catch(() => {});
			}
			
		}
	}
</script>

<style scoped lang="scss">
	.el-box{
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		width: 100%;
		height: 600px;
	}
	.list-box{
		flex: 1;
	}
	.page-limit{
		display: flex;
		width: 100%;
		justify-content: center;
		padding-top: 20px;
	}
	
</style>
<style>
	.el-dialog__body{
		padding: 10px 20px 20px!important;
	}
</style>